How do I redirect standard output to a file in Perl? [closed]
Posted
by rockyurock
on Stack Overflow
See other posts from Stack Overflow
or by rockyurock
Published on 2010-04-20T10:08:08Z
Indexed on
2010/04/20
12:43 UTC
Read the original article
Hit count: 210
I want to send standard output to the file "my_output.txt" but failed.
Here's the output:
inside value loop
------------------------------------------------------------
Server listening on UDP port 5001
Receiving 1470 byte datagrams
UDP buffer size: 108 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.16.2 port 5001 connected with 192.168.16.1 port 3189
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 3] 0.0- 5.0 sec 2.14 MBytes 3.61 Mbits/sec 0.369 ms 0/ 1528 (0%)
inside value loop3
clue1
clue2
inside value loop4
one iperf completed
***************************************
When I enable the local *STDOUT;
in below code then I could see the above output on command prompt display (ofcourse server is sending some data):
my $file = 'my_output.txt';
use Win32::Process;
print"inside value loop\n";
# redirect stdout to a file
#local *STDOUT;
open STDOUT, '>', $file
or die "can't redirect STDOUT to <$file> $!";
Win32::Process::Create(my $ProcessObj,
"D:\\IOT_AUTOMATION_UTILITY\\_SATURDAY_09-04-10\\adb_cmd.bat",
"adb shell /data/app/iperf -u -s -p 5001",
0,
NORMAL_PRIORITY_CLASS,
".") || die ErrorReport();
#$alarm_time = $IPERF_RUN_TIME+10; #20sec
#$ProcessObj->Wait(40);
#print"inside value loop2\n";
#sleep $alarm_time;
sleep 40;
$ProcessObj->Kill(0);
sub ErrorReport{
print Win32::FormatMessage( Win32::GetLastError() );
}
© Stack Overflow or respective owner